package hanshunping.easy;

/**
 * create by: 蔡博
 * description: TODO
 * create time: 2022/6/7 20:48
 * 包装类和常用类
  * @Param: null
 * @return
 */
public class Wrappers {
    public static void main(String[] args) {
        String test = "abcdefghijklmnopqrstuvwxyz";
        TurnString turnstr = new TurnString();
        String res = turnstr.reverse(test,1,20);
        String res2 = turnstr.reverse2(test,1,20);
        System.out.println(res+"\n"+res2);
    }
}





/**
 * create by: 蔡博
 * description: TODO
 * create time: 2022/6/7 22:51
 * 字符串指定位置翻转
  * @Param: null
 * @return
 */
class TurnString {
    public String reverse(String str, int i1, int i2) {
        StringBuilder newstr = new StringBuilder();
        for (int i = i2; i >= i1; i--) {
            newstr.append(str.charAt(i));
        }
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < i1; i++) {
            res.append(str.charAt(i));
        }
        res.append(newstr);
        for (int i = i2 + 1; i < str.length(); i++) {
            res.append(str.charAt(i));
        }
        return res.toString();
    }

    public String reverse2(String str, int i1, int i2) {
        char[] chars = str.toCharArray();
        int e =0;
        for (int i = i1, j = i2; i < j; i++, j--) {
            char temp = chars[i];
            chars[i] = chars[j];
            chars[j] = temp;
        }
        return new String(chars);
    }
}